package entility;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StringNormalize{


	

	public Map<String, List<String>> getFileContent(File folder)
	{
		if(!folder.isDirectory())
		{
			System.out.println("The current file isn't a folder");
			return null;
		}
		
		Map<String, List<String> > mapFile = new HashMap<String, List<String>>();
		for(File file: folder.listFiles())
		{
			List<String > fileContet = this.readFile(file.getPath());
			mapFile.put(file.getName(), fileContet);
		}
		return mapFile;
	}

	

	public List<String> readFile(String file) 
	{
		List<String> ids  = new ArrayList<String>();
		String line = null;

		BufferedReader reader;
		try {
			reader = new BufferedReader(new FileReader(file));
			while ((line = reader.readLine()) != null) {

				ids.add(line);
			}
			reader.close();


			return ids;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;

	}

	public void writeFile(String file, String content) {  

		PrintWriter writer;
		try {
			writer = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
			writer.println(content);
			writer.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	} 


	public String normalize(String line) {
		
		String newLine = line.replaceAll("\\.|,|\\\"|\\\t|�|\\?|--|\\^|#|\\(|\\)|\\[|\\]|_|\\$|\\*|=|\\|", "").trim().toLowerCase();
		newLine = newLine.replaceAll(";|,|\\+|\\-|/|>|<", " ");
		return newLine;
	}



}